import { uniSection, uniEasyinput, uniIcons } from '@dcloudio/uni-ui';

export default {
  components: {
    uniSection,
    uniEasyinput,
    uniIcons
  },
  data() {
    return {
      newMemo: '',
      memos: [],
	  text:"备忘录",
    }
  },
  onLoad() {
    this.loadMemos();
  },
  methods: {
    addMemo() {
      const text = this.newMemo.trim();
      if (!text) return;
      this.memos.unshift({ id: Date.now(), text, done: false });
      this.newMemo = '';
      this.saveMemos();
    },
    deleteMemo(index) {
      this.memos.splice(index, 1);
      this.saveMemos();
    },
    toggleDone(index) {
      this.memos[index].done = !this.memos[index].done;
      this.saveMemos();
    },
    saveMemos() {
      uni.setStorageSync('memos', this.memos);
    },
    loadMemos() {
      const data = uni.getStorageSync('memos');
      if (Array.isArray(data)) {
        // 兼容老数据
        this.memos = data.map(item => ({...item, done: item.done || false}));
      }
    },
    formatTime(ts) {
      const d = new Date(ts);
      return `${d.getMonth()+1}-${d.getDate()} ${d.getHours()}:${d.getMinutes()<10?'0':''}${d.getMinutes()}`;
    }
  }
} 